package com.example.thornchg.yc_plane_game;

import android.database.sqlite.SQLiteDatabase;
import android.view.MotionEvent;

import org.cocos2d.extensions.scroll.CCScrollView;
import org.cocos2d.layers.CCLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCLabel;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.sound.SoundEngine;
import org.cocos2d.transitions.CCFadeTransition;
import org.cocos2d.transitions.CCFlipXTransition;
import org.cocos2d.transitions.CCJumpZoomTransition;
import org.cocos2d.types.CGPoint;
import org.cocos2d.types.CGRect;
import org.cocos2d.types.CGSize;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

class StartReadyLayer extends CCLayer {
    private CGSize winSize;
    private CGRect cgRect_rank;
    private CCSprite ccSprite_start_button;
    private CGRect cgRect_start;

    public StartReadyLayer() {
        winSize = CCDirector.sharedDirector().getWinSize();
        CombatMap combatMap = new CombatMap(this);

        CCSprite ccSprite = CCSprite.sprite("start.png");
        ccSprite.setScale(2);
        ccSprite.setPosition(ccp(winSize.getWidth() / 2, winSize.getHeight() / 4 * 3));
        ccSprite.setColor(ccc3(255, 255, 255));
        addChild(ccSprite);
        ccSprite_start_button = CCSprite.sprite("start_button.png");
        ccSprite_start_button.setScale(2);
        ccSprite_start_button.setPosition(winSize.getWidth() / 2, winSize.getHeight() / 4);
        addChild(ccSprite_start_button);
        cgRect_start = CGRect.make(
                ccSprite_start_button.getPosition().x - ccSprite_start_button.getBoundingBox().size.width / 2,
                ccSprite_start_button.getPosition().y - ccSprite_start_button.getBoundingBox().size.height / 2,
                ccSprite_start_button.getBoundingBox().size.width,
                ccSprite_start_button.getBoundingBox().size.height);

        CCSprite ccSprite_rank_button = CCSprite.sprite("Ranking.png");
        ccSprite_rank_button.setScale(2);
        ccSprite_rank_button.setPosition(winSize.getWidth() / 2, winSize.getHeight() / 3);
        addChild(ccSprite_rank_button);
        cgRect_rank = CGRect.make(
                ccSprite_rank_button.getPosition().x - ccSprite_rank_button.getBoundingBox().size.width / 2,
                ccSprite_rank_button.getPosition().y - ccSprite_rank_button.getBoundingBox().size.height / 2,
                ccSprite_rank_button.getBoundingBox().size.width,
                ccSprite_rank_button.getBoundingBox().size.height);
        setIsTouchEnabled(true);
    }

    @Override
    public boolean ccTouchesBegan(MotionEvent event) {
        CGPoint cgPoint = convertTouchToNodeSpace(event);
        if (CGRect.containsPoint(cgRect_start, cgPoint)) {
            SoundEngine.sharedEngine().playEffect(CCDirector.sharedDirector().getActivity(),
                    R.raw.start_click);
            CCScene ccScene = CCScene.node();
            ccScene.addChild(new GameLayer());
            CCFadeTransition ccFadeTransition=CCFadeTransition.transition(.3f,ccScene);
            CCDirector.sharedDirector().runWithScene(ccFadeTransition);
        } else if (CGRect.containsPoint(cgRect_rank, cgPoint)) {
            CCScene ccScene=CCScene.node();
            ccScene.addChild(new RankLayer());
            CCFlipXTransition ccFlipXTransition=CCFlipXTransition.transition(1f,ccScene,1);
            CCDirector.sharedDirector().runWithScene(ccFlipXTransition);


        }

        return super.ccTouchesBegan(event);
    }
}
